<?php
namespace Api\Controller;
use Api\Logic;

class AuthController extends ApibaseController
{

function register(){
    if (IS_POST){       
        $username=I('post.username');
        $password=md5(I('post.password'));

        $logic=new UserLogic();
        $ret=$logic->register($username,$password);

        switch ($ret){
            case 0:
            {
                $this->success($uid,'用户用户身份验证通过。');
                break;
            }
            case -1:
            {
                $this->error(-1,'用户已经注册');
                break;

            }
            case -2:
            {
                $this->error(-2,'注册失败。');
                break;
            }
            default:{
                $this->error(-3,'注册失败。');
                break;
            }
        }

    }else{
        $this->error(-3,'注册失败。');
    }
}

    function register2(){
        if (IS_POST){
        $userModel = D('Home/User'); //M('user')
        $username=I('post.username');
        $password=md5(I('post.password'));

        $user=array();
        $user['username']=$username;
        $user['password']=$password;

        if ($userModel->where(array('username'=>$username))->count()>0){
           $this->error(-1,'用户已经注册');
        }

        $uid=$userModel->add($user);             
        if ($uid) {
            //验证通过
            $this->success($uid,'用户用户身份验证通过。');
        } else {
            $this->error(-2,'注册失败。');
        }
    }else{
        $this->error(-3,'注册失败。');
    }
    }
}